import { CoolController, BaseController, QueryOp } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { VisitInfoEntity } from '../../entity/info'; 
import { VisitInfoService } from '../../service/info'; 

/**
 * visitInfo模块-访问信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: VisitInfoEntity,
  service: VisitInfoService,
})
export class AdminVisitInfoController extends BaseController {
    @Inject()
    ctx;

    @Inject()
    visitInfoService: VisitInfoService;

    @Post('/updateVisitInfo', { summary: '更新信息' })
    async updateVisitInfo(@Body() body) {
      return this.ok(
        await this.visitInfoService.updateVisitInfo(this.ctx.user.id, body)
      );
    }

    @Post('/detail', { summary: '获取访问信息详情' })
    async detail(@Body('id') id: number) {
        return this.ok(await this.visitInfoService.info(id));
    }

    async page() {
      const { body } = this.baseCtx.request;
      const op = {} as QueryOp
      // let op = this.curdOption.pageQueryOp as QueryOp
      op.where = async (ctx) => {
        return [
          [
            { userId: ctx.admin.userId },
          ],
        ];
      }
      return this.ok(await this.service.page(body, op, this.connectionName));
    }
}
